<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page session="false" %>
<%@ page isELIgnored ="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<script type="text/javascript">
//<![CDATA[
(function(){
	if(typeof Properties === "undefined" ){
		Properties = {
			_dlgGroupNewId:"dialog_properties_group_new",
			_dlgPropertiesNewId : "dialog_properties_new",
			refresh:function(group){
				if(group){
					if(isNaN(group))
						for(var key in Properties.groupCode)
							if(group==Properties.groupCode[key]){
								group = key;
								break;
							}
					if(isNaN(group))return;
					dijit.byId("ext_properties_detail").selectChild(dijit.byId("properties_group_"+group));
					Properties.store[group] = new dojo.data.ItemFileWriteStore({url:'../../config/properties/group/'+Properties.groupCode[group]+'/properties.json'});
					dijit.byId('properties_grid_'+group).setStore(Properties.store[group]);
				}
				else dijit.byId("ext_properties").refresh();
			},
			callNewProperty:function(){
				var num = dijit.byId("ext_properties_detail").selectedChildWidget.get("id").replace("properties_group_","");
				this.dlg = $ku.showDialog({
					id:Properties._dlgPropertiesNewId,
					url:"../../config/properties/new.html?groupcode="+Properties.groupCode[num],
					title:$ksub(KppModule.commonResource.operCreate,[SysAdmin._resource.properties]),
					resource:SysAdmin._resource,
					style:"width:300px;height:190px;"});
			},
			callNewGroup:function(){
				this.dlg = $ku.showDialog({
					id:Properties._dlgGroupNewId,
					url:"../../config/properties/group/new.html",
					title:$ksub(KppModule.commonResource.operCreate,[KppModule.commonResource.group]),
					resource:SysAdmin._resource,
					style:"width:300px;height:135px;"});
			},
			gridStructure:[
	       		{cells:[
					{field:"_item",name:KppModule.commonResource.sn,formatter:KppModule.sno,width:"40px",filterable:false},
					{field:"key",name:SysAdmin._resource.properties,formatter:$kt.escapeBlank,width:"200px",datatype:"string"},
					{field:"value",name:KppModule.commonResource.value,formatter:$kt.escapeBlank,editable:true,width:"auto",datatype:"string"}
	       		]}
			],
			store:[],
			groupCode:[]
		};
	};
	$kdom.appendDojoProp("cp_properties_nav","content","<img class=\"icon_s_admin icon_s_admin_gear\" src=\"${pageContext.request.contextPath}/assets/images/blank.gif\" /><span>"+SysAdmin._resource.properties+"</span>");
	$kdom.appendDojoProp("btn_properties_new","label",$ksub(KppModule.commonResource.operCreate,[SysAdmin._resource.properties]));
	$kdom.appendDojoProp("btn_properties_group_new","label",$ksub(KppModule.commonResource.operCreate,[KppModule.commonResource.group]));
	var groupI18nLabel;
	<c:forEach varStatus="loopStatus" items="${groups}" var="group">
		groupI18nLabel = SysAdmin._resource["propertiesGroup${group.code}"];
		$kdom.appendDojoProp("properties_group_${loopStatus.index}","title",groupI18nLabel?groupI18nLabel:"${group.code}");
		Properties.store[${loopStatus.index}] = new dojo.data.ItemFileWriteStore({url:'../../config/properties/group/${group.code}/properties.json'});
		Properties.groupCode[${loopStatus.index}]='${group.code}';
	</c:forEach>
})();

//]]>
</script>

<span style="display:none">To solve IE7/8 script event tag problem.</span>
<div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'sidebar',liveSplitters:true" class="contentWrapper" style="margin:-2px;height:100%">
	<div id="cp_properties_nav" data-dojo-type="dijit.layout.ContentPane"  data-dojo-props="region:'top'" class="contentWrapperRight contentPaneNav" style="border:none;margin:-5px;padding:10px 0 10px 10px;background-color:transparent">
	</div>
	<div data-dojo-type="dijit/layout/ContentPane"  data-dojo-props="region:'top'" style="border:none;background-color:transparent;padding:0 4px;margin:-4px 0;">
		<div data-dojo-type="dijit/form/Button" id="btn_properties_new" onclick="Properties.callNewProperty()" data-dojo-props="iconClass:'icon_s_admin icon_s_admin_gear_new'">
		</div>
		<div data-dojo-type="dijit/form/Button" id="btn_properties_group_new" onclick="Properties.callNewGroup()" data-dojo-props="iconClass:'icon_s_admin icon_s_admin_gear_triple'">
		</div>
	</div>
	<div id="ext_properties_detail" data-dojo-type="dijit/layout/TabContainer" data-dojo-props="tabPosition:'top',region:'center'" style="padding:0 2px;" >
		<c:forEach items="${groups}" var="group" varStatus="loopStatus">
			<div id="properties_group_${loopStatus.index}" data-dojo-type="dijit.layout.ContentPane" >
				<div data-dojo-type="dojox/grid/DataGrid" id="properties_grid_${loopStatus.index}" class="nihilo kpp"
					data-dojo-props="structure:Properties.gridStructure,store:Properties.store[${loopStatus.index}],canSort:function(){return false;},style:'margin:2px;'" >
					<script type="dojo/on" data-dojo-event="applyEdit" data-dojo-args="rowIndex">
					//<![CDATA[
					if(this.getItem(rowIndex).value=="null"||this.getItem(rowIndex).value=="undefined"){
						this.getItem(rowIndex).value=" ";
						return;
					}
					var options = {
						domain:SysAdmin._resource.properties,
						refresh:Properties.refresh,
						refreshArgs:'${loopStatus.index}',
						url:"../../config/properties/"+this.getItem(rowIndex).key+".json",
						successMsg:false,
						content:{"value":this.getItem(rowIndex).value},
						resource:SysAdmin._resource
					};
					KppModule.restProxy(options).putUpdate();
					//]]>
					</script>
				</div>
			</div>
		</c:forEach>
	</div>
</div>